<template>
  <div id="search">
    <div class="search_tittle">
      <p>以下是<strong>“{{ getSearch }}”</strong>相关的搜索</p>
    </div>
    <div class="search_main " v-if="searchList.length">
      <ShowListVue v-for="item in searchList" :key="item.id" :list="item"></ShowListVue>
    </div>
    <el-empty description="暂无相关搜索" v-else></el-empty>

  </div>
</template>

<script>
import ShowListVue from '@/components/userComponents/ShowList.vue'
import { getSearchService } from '@/api/repair'
export default {
  data () {
    return {
      searchList: []
    }
  },
  created () {
    this.getSearchList()
  },
  methods: {
    async getSearchList () {
      const res = await getSearchService(this.getSearch)
      this.searchList = res.data || []
    }
  },
  watch: {
    // 监听getSearch的变化
    getSearch (newValue, oldValue) {
      if (oldValue === newValue) return
      if (!newValue) return
      this.getSearchList(newValue)
    }
  },
  computed: {
    getSearch () {
      return this.$route.params.search
    }
  },
  components: { ShowListVue }

}
</script>

<style lang="less" scoped>
#search{
  background-color: #fff;
  .search_tittle{
    text-align: center;
    font-size: 14px;
    strong{
      font-size: 16px;
    }
  }
  .search_main{
  margin: 0 auto;
  padding: 0 100px;
  // padding-left: 80px;
  // width: 100%;
  display: flex;
  // justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}
}

</style>
